package org.chengn.level_hard.context828;

public class Context828 {
    int ans = 0;
    public int uniqueLetterString(String s) {
        checkNum(s);
        return ans;    }

    void checkNum(String s) {
        char ch = 'A';
        for (int i = 0; i < 26; ++i) {
            char idxCh = (char)(ch + i);
            int l = 0, mid = -1, r = -1;
            for (int j = 0; j < s.length(); ++j) {
                if (s.charAt(j) == idxCh) {
                    if (mid == -1) {
                        mid = j;
                        continue;
                    }
                    r = j - 1;
                    ans += r - l + 1 + (mid - l) * (r - mid);
                    l = mid + 1;
                    mid = j;
                }

            }
            if (mid != -1) {
                r = s.length() - 1;
                ans += r - l + 1 + (mid - l) * (r - mid);
            }
        }
    }
}
